package com.advance.springcloud.gateway.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 功能描述: 
 * @author  advance
 * @date  2021/3/1 20:14
 */
@Configuration
public class GatewayConfig {

    @Bean
    public RouteLocator customerRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes ()
                .route (r -> r.path ("/api/user/**")
                        .filters (f -> f.stripPrefix (2))
                        .uri ("lb://user-service")
                        .id ("user-service")
                )
                .route(r -> r.path ("/api/auth/**")
                        .filters (f -> f.stripPrefix (2))
                        .uri ("lb://auth-service")
                        .id ("auth-service")
                )
                .build ();
    }
}
